package com.stu.status;


import java.util.ArrayList;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.stu.aq.*;
import com.stu.widget.*;

public class IndicatorFragment extends Fragment {
	
	private final class Indicator {
		public final static int MOTOR = 0;
		public final static int MODE = 1;
		public final static int HOLD = 2;
	}
	private ArrayList<IndicatorView> indicators;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
	  Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.indicators, container, false);
		indicators = new ArrayList<IndicatorView>();
		IndicatorView m = (IndicatorView)v.findViewById(R.id.motorStatusLight);
		m.setText("Disarmed", "Armed");
		m.setState( false );
		indicators.add( m );
		m = (IndicatorView)v.findViewById(R.id.flightModeLight);
		m.setText("Attitude", "Rate");
		m.setState( false );
		indicators.add( m );
		m = (IndicatorView)v.findViewById(R.id.altitudeHoldLight);
		m.setText("Off", "On");
		m.setState( false );
		indicators.add( m );
		return v;
	}

	/**
	 * @param isArmed
	 */
	public void setMotorStatus( boolean isArmed ) {
		indicators.get(Indicator.MOTOR).setState( isArmed );
		indicators.get(Indicator.MOTOR).invalidate();
	}

	public void setModeStatus( boolean isRate ) {
		indicators.get(Indicator.MODE).setState( isRate );
		indicators.get(Indicator.MODE).invalidate();
	}

	public void setHoldStatus( boolean isOn ) {
		indicators.get(Indicator.HOLD).setState( isOn );
		indicators.get(Indicator.HOLD).invalidate();
	}
	
	public void clear() {
		for( IndicatorView i : indicators ) {
			i.setState( false );
			i.invalidate();
		}
	}
}
